pub type IndexResult<T> = Result<T, IndexError>;

#[derive(Debug, Clone)]
pub enum IndexError {
    Io(String),
    Sled(sled::Error),
}

impl std::fmt::Display for IndexError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            Self::Io(err) => write!(f,"Error io:{}", err),
            Self::Sled(err) => write!(f,"Error sled:{}", err),
        }
    }
}

impl std::error::Error for IndexError {}

impl From<std::io::Error> for IndexError {
    fn from(value: std::io::Error) -> Self {
        Self::Io(format!("{value}"))
    }
}

impl From<sled::Error> for IndexError {
    fn from(value: sled::Error) -> Self {
        Self::Sled(value)
    }
}